﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace SunshineAirlines
{
    class DBHelper
    {
        private static readonly string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["SQLConnString"].ToString(); 

        //public static SqlConnection cn = new SqlConnection("Data Source=DESKTOP-HGVK93A;initial catalog=Session1;uid=sa;pwd=111");
        private static SqlConnection cn = new SqlConnection(connStr);
        public static int items = 0;//FoodServices使用
        public static int amount = 0;//FoodServices使用
        public static double payment = 0f;//FoodServices使用
        public static int[] fooid = new int[18];
        public static Dictionary<int, double> foodAmount = new Dictionary<int, double>();
        //public static int Executesql(string sql)
        //{
        //    cn.Open();
        //    SqlCommand cmd = new SqlCommand(sql, cn);
        //    int result = cmd.ExecuteNonQuery();
        //    cn.Close();
        //    return result;
        //}

        public static object ExecuteScalar(string sql)
        {
            cn.Open();
            SqlCommand cmd = new SqlCommand(sql, cn);
            object result = cmd.ExecuteScalar();
            cn.Close();
            return result;
        }
        public static DataTable ExecuteTable(string sql)
        {
            cn.Open();
            SqlDataAdapter cmd = new SqlDataAdapter(sql, cn);
            DataSet ds = new DataSet();
            cmd.Fill(ds);
            cn.Close();
            return ds.Tables[0];
        }
    }
}
